<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.util.*" session="true"%>
<%@ page import = "pe.com.deuda.bd.dao.ConsultaDAO"%>
<%@ page import = "pe.com.deuda.bd.model.Deudor"%>
<%@ page import = "java.util.ArrayList"%>
<%@ page import = "java.util.List"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<script>
       function seleccionar(codigo, ix){
           if (document.frmDeuda.deudor.length!=undefined ){
            for(var i = 0; i < document.frmDeuda.deudor.length; i++){
                if(document.frmDeuda.deudor[i].type == "checkbox")    {
                    if (i==ix){
                        if (document.frmDeuda.deudor[i].checked==true){
                            document.frmDeuda.codigo.value=codigo;
                        }
                        else{
                            document.frmDeuda.codigo.value='';
                        }
                    }
                    else{
                        document.frmDeuda.deudor[i].checked=false;
                    }
                }
            }
           }
           else{
               document.frmDeuda.codigo.value=codigo;
           }
       }

    function submitform()
    {
        document.forms["frmDeuda"].submit();
    }
</script>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="/WebDeudas/css/estilo.css" rel="stylesheet" type="text/css" />
        <title>Resultado Busqueda</title>
    </head>
    <body>
        <p>&nbsp;</p>
        <table width="80%">
            <tr>
                <td width="30%">&nbsp;</td>
                <td width="50%">&nbsp;</td>
                <td width="20%">Bienvenido <%=session.getAttribute("nombre") %> ! </td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td>&nbsp; </td>
                <td></td>
                <td></td>
            </tr>
        </table>
        <form name="frmDeuda" id="frmDeuda" action="DetalleDeudor.jsp" method="post">
            <input type="text" value="" id="codigo" name="codigo"  style="visibility: hidden;" />
        <table width="80%" border="1" cellpadding="0" cellspacing="0">
            <tr>
                <th width="25%">Nombre</th>
                <th width="25%">Ap. Paterno</th>
                <th width="25%">Ap. Materno</th>
                <th width="15%">DNI</th>
                <th width="10%">Seleccionar</th>
            </tr>
            <%
            ConsultaDAO dao=new ConsultaDAO();
            List<Deudor> listaDeudor = new ArrayList<Deudor>();
            listaDeudor=dao.getListaDeudor(request.getParameter("txBusca").toString() );
            for (int row = 0; row < listaDeudor.size(); row++) {
                Deudor oDeudor = new Deudor();
                oDeudor = listaDeudor.get(row);
            %>
            <tr>
                <td><%=oDeudor.getNombre().toString() %></td>
                <td><%=oDeudor.getAppaterno().toString() %></td>
                <td><%=oDeudor.getApmaterno().toString() %></td>
                <td><%=oDeudor.getDni().toString()%></td>
                <td><input type="checkbox" name="deudor" id="deudor"  onclick="javascript: seleccionar('<%= oDeudor.getIddeudor().toString()%>','<%=row%>');"> </td>
            </tr>
            <%
            }
            %>

        </table>
                 <br><br><br>

        <input type=submit  value='Ver Detalle'>
        <input type=button onClick="location.href='RegistroDeudor.jsp'" value='Registrar deudor'>
        <input type=button onClick="location.href='Reclamo.jsp'" value='Registrar Reclamo'>
        <input type=button onClick="location.href='BuscaDeudor.jsp'" value='Lista Deudor'>
        <input type=button onClick="location.href='BuscaReclamo.jsp'" value='Lista Reclamo'>
        </form>


    </body>
</html>
